import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('BgControl')
export class BgControl extends Component {
    
    @property(Node)
    bg01: Node = null;

    @property(Node)
    bg02: Node = null;

    @property
    speed = 200;

    
       
    start() {

    }

    update(deltaTime: number) {
        let position01 = this.bg01.position;                      
        this.bg01.setPosition(position01.x , position01.y - this.speed * deltaTime, position01.z);
        let position02 = this.bg02.position;                           
        this.bg02.setPosition(position02.x, position02.y - this.speed * deltaTime, position02.z);
        
        if(this.bg01.position.y < -1000){
            this.bg01.setPosition(position01.x, this.bg02.position.y +1000, position01.z);
        }
        if(this.bg02.position.y < -1000){
            this.bg02.setPosition(position02.x, this.bg01.position.y +1000, position02.z);
        }
        
    }
}


